package com.starinside.wp.repository.impl;

import com.starinside.wp.domain.Praises;
import com.starinside.wp.foundation.vo.PraisesVO;
import com.starinside.wp.repository.BaseNativeSqlRepository;
import com.starinside.wp.repository.PraisesNativeRepository;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class PraisesNativeRepositoryImpl extends BaseNativeSqlRepository implements PraisesNativeRepository {


    @Override
    public List<PraisesVO> findByUidAndFid(String uid, String fid) {
        String sql = "SELECT p.id, p.uid, p.fid,p.created,u.name as username FROM praises p left join users u on p.uid = u.id " +
                "where p.uid=?1 and p.fid=?2 " +
                "order by created";

//        sql = String.format(sql, uid, fid);

        List params =  new ArrayList();
        params.add(sql);
        params.add(fid);

        List<PraisesVO> result = sqlObjectList(sql, params, PraisesVO.class);

        return result;
    }
}
